package com.labweb.beans;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import com.labweb.entidades.Software;
import com.labweb.servicos.SoftwareService;

public class CadastroSoftware {
	Software software;

	public CadastroSoftware() {
		this.software = new Software();
	}
	
	public String inicializar() {
		this.software = new Software();
		
		return "cadastroSoftware";
	}
	
	public Software getSoftware() {
		return software;
	}

	public void setSoftware(Software software) {
		this.software = software;
	}
	
	public void salvar(ActionEvent event) {
		FacesContext context = FacesContext.getCurrentInstance();
		try {
			new SoftwareService().salvar(this.software);
			this.software = new Software();
			FacesMessage msg = new FacesMessage(
			"Software salvo com sucesso!");
			msg.setSeverity(FacesMessage.SEVERITY_INFO);
			context.addMessage(null, msg);
		} catch (Exception e) {
			e.printStackTrace();
			FacesMessage msg = new FacesMessage(
			"Erro inesperado ao salvar conta!");
			msg.setSeverity(FacesMessage.SEVERITY_ERROR);
			context.addMessage(null, msg);
		}
	}
}
